// User 类定义
export class User {
    constructor(data = {}) {
        this.userId = data.userId || 0
        this.userName = data.userName || ''
        this.userPassword = data.userPassword || ''
        this.userAccount = data.userAccount || ''
        this.userAvatar = data.userAvatar || ''
        this.userGender = data.userGender || '男'
        this.userRole = Number(data.userRole)==0? 0 : 1
        this.userClass = data.userClass || ''
        this.userSchool = data.userSchool || ''
    }

    // 从JSON数据创建User实例
    static fromJson(json) {
        return new User(json)
    }

    // 转换为JSON对象
    toJson() {
        return {
            userId: this.userId,
            userName: this.userName,
            userPassword: this.userPassword,
            userAccount: this.userAccount,
            userAvatar: this.userAvatar,
            userGender: this.userGender,
            userRole: this.userRole,
            userClass: this.userClass,
            userSchool: this.userSchool
        }
    }

    // 重置用户数据
    reset() {
        this.userId = 0
        this.userName = ''
        this.userPassword = ''
        this.userAccount = ''
        this.userAvatar = ''
        this.userGender = '男'
        this.userRole = 1
        this.userClass = ''
        this.userSchool = ''
    }
};

// 新增 UserUpdateRequest 类
export class UserUpdateRequest {
    constructor(data = {}) {
        this.userId = data.userId || 0
        this.userName = data.userName || ''
        this.userPassword = data.userPassword || ''
        this.userAvatar = data.userAvatar || ''
        this.userGender = data.userGender || ''
        this.userRole = data.userRole || 1
    }

    // 从JSON数据创建UserUpdateRequest实例
    static fromJson(json) {
        return new UserUpdateRequest(json)
    }

    // 转换为JSON对象
    toJson() {
        return {
            userId: this.userId,
            userName: this.userName,
            userPassword: this.userPassword,
            userAvatar: this.userAvatar,
            userGender: this.userGender,
            userRole: this.userRole
        }
    }
};